﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../impl/protocol_impl.h"
#include "../impl/bzip2_impl.h"
#include "../impl/lzma_impl.h"
#include "../impl/zlib_impl.h"
#include "sys_data.h"

///////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos_compress
{

    sys_data::sys_data( xos_container::i_container * pContainer ) : m_pContainer( pContainer )
    {
        m_pAlloc = 0;
        m_pMgr = 0;
    }

    sys_data::~sys_data()
    {
    }

    int sys_data::init()
    {
        int nRet = 0;

        if( 0 == nRet )
        {
            nRet = m_pContainer->common()->create( xos_common::OBJ_ALLOC, ( void ** )&m_pAlloc );
        }

		if( 0 == nRet )
		{
			nRet = bzip2_impl::init_all();
		}

		if( 0 == nRet )
		{
            nRet = lzma_impl::init_all();
		}

		if( 0 == nRet )
		{
            nRet = zlib_impl::init_all();
		}

        if( 0 == nRet )
        {
            nRet = protocol_impl::init_all();
        }

        return nRet;
    }

    int sys_data::term()
    {
        int nRet = 0;

        protocol_impl::term_all();
        bzip2_impl::term_all();
        zlib_impl::term_all();
        lzma_impl::term_all();

		xos_stl::release_interface( m_pAlloc );

        m_pContainer = 0;
        m_pMgr = 0;

        return nRet;
    }

} // xos_compress
